package com.quwan.manager.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.common.query.LambdaQueryWrapperX;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TCircleType;
import com.quwan.entity.TMemberAsk;
import com.quwan.manager.service.ICircleTypeService;
import com.quwan.mapper.TCircleTypeMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author laozhang
 * @date 2022/3/17
 */
@Service
@RequiredArgsConstructor
public class CircleTypeServiceImpl implements ICircleTypeService {

    private final TCircleTypeMapper circleTypeMapper;

    @Override
    public PageResult<TCircleType> getCircleTypeListPage(int page, int size, String name,Integer status) {
        LambdaQueryWrapperX<TCircleType> wrapper = new LambdaQueryWrapperX<TCircleType>()
                .orderByDesc(TCircleType::getCreateTime);
        if(StringUtils.isNotBlank(name)) {
            wrapper.like(TCircleType::getTypeName,name);
        }
        if(status !=null) {
            wrapper.eq(TCircleType::getStatus,status);
        }

        Page<TCircleType> circleTypePage = circleTypeMapper.selectPage(new Page<>(page, size), wrapper);
        List<TCircleType> reslist = circleTypePage.getRecords();
        PageResult<TCircleType> result = new PageResult<TCircleType>()
                .setCurrent(circleTypePage.getCurrent())
                .setPages(circleTypePage.getPages())
                .setSize(circleTypePage.getSize())
                .setTotal(circleTypePage.getTotal())
                .setRecords(reslist);
        return result;
    }

    @Override
    public List<TCircleType> getCircleTypeList(String name,Integer status) {
        LambdaQueryWrapperX<TCircleType> wrapper = new LambdaQueryWrapperX<TCircleType>()
                .orderByDesc(TCircleType::getCreateTime);
        if(StringUtils.isNotBlank(name)) {
            wrapper.like(TCircleType::getTypeName,name);
        }
        if(status !=null) {
            wrapper.eq(TCircleType::getStatus,status);
        }
        return circleTypeMapper.selectList(wrapper);

    }

    @Override
    public boolean addCircleType(TCircleType circleType) {
        return circleTypeMapper.insert(circleType) ==1;
    }

    @Override
    public boolean updateCircleType(TCircleType circleType) {
        return circleTypeMapper.updateById(circleType) ==1;
    }

    @Override
    public TCircleType detailCircleType(Integer id) {
        return circleTypeMapper.selectById(id);
    }

    @Override
    public boolean delCircleType(Integer id) {
        return circleTypeMapper.deleteById(id) == 1;
    }
}
